import { get, post } from '/@/api/http'
import { DatasetConfig } from '/@/datav/types/data-source';
//这是后端网关的=路由
const serverContextPath = '/example-server'

/**
 * 大屏
 */
export interface Screen {
	id: string;
	name: string;
	shareKey: string;
	status: string;
	thumbnail?: string;
	groupId: string;
	createTime: string;
	updateTime: string;
	password: string;
	config?: any;
}

/**
 * 大屏分组
 */
export interface ScreenGroup {
	id: string;
	name: string;
	createTime: string;
	updateTime: string;
}

export interface PosterPage {
	id: string;
	userId: string;
	posterKey: string;
	name: string;
	posterWidgetList: any[];
	posterConfig: any;
	createTime: string;
	updateTime: string;
}

export interface PosterFormLink {
	id: string;
	userId: string;
	formKey: string;
	posterKey: string;
	name: string;
	fields: [];
	createTime: string;
	updateTime: string;
}

export interface ProjectTemplate {
	id: string;
	name: string;
	description: string;
	size: String[];
	snapshot: string;
	thumbnail: string;
	config: any;
}

export interface DashboardPage {
	id: string;
	userId: string;
	shareKey: string;
	name: string;
	status: string;
	publishStatus: string;
	componentList: any[];
	pageConfig: any;
	createTime: string;
	updateTime: string;
}

export const reportApi = {
    /**
     * 分页查询报表数据源管理
     * @param data {
          page: pagination.page,
          pageSize: pagination.pageSize,
          param: {...},
        }
     * @returns
     */
    queryReportDataSourceListPage: (data: any) => {
        return post({
            url: serverContextPath + '/report/dataSource/page',
            data: data,
        })
    },
    /**
     * 新增报表数据源管理
     * @param dataForm 参数
     * @returns
     */
    saveReportDataSourceInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/dataSource/save',
            data: dataForm,
        })
    },
    /**
     * 修改报表数据源管理
     * @param dataForm 参数
     * @returns
     */
    updateReportDataSourceInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/dataSource/update',
            data: dataForm,
        })
    },

    /**
     * 删除报表数据源管理
     * @param id 主键
     * @returns
     */
    deleteReportDataSourceInfo: (id: string) => {
        return post({
            url: serverContextPath + '/report/dataSource/remove/' + id,
        })
    },
    getDataSourceAllList: () => {
        return get({
            url: serverContextPath + '/report/dataSource/list',
        })
    },
    testDataSourceConnect: (data: any) => {
        return post({
            url: serverContextPath + '/report/dataSource/testConnection',
            data: data,
        })
    },
    /**
     * 分页查询数据大屏分组
     * @param data {
          page: pagination.page,
          pageSize: pagination.pageSize,
          param: {...},
        }
     * @returns
     */
    queryReportScreenGroupListPage: (data: any) => {
        return post({
            url: serverContextPath + '/report/screenGroup/page',
            data: data,
        })
    },
    /**
     * 新增数据大屏分组
     * @param dataForm 参数
     * @returns
     */
    saveReportScreenGroupInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/screenGroup/save',
            data: dataForm,
        })
    },
    /**
     * 修改数据大屏分组
     * @param dataForm 参数
     * @returns
     */
    updateReportScreenGroupInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/screenGroup/update',
            data: dataForm,
        })
    },

    /**
     * 删除数据大屏分组
     * @param id 主键
     * @returns
     */
    deleteReportScreenGroupInfo: (id: string) => {
        return post({
            url: serverContextPath + '/report/screenGroup/remove/' + id,
        })
    },
    /**
     * 获取大屏分组列表
     */
    getScreenGroups() {
        return get<ScreenGroup[]>({
            url: serverContextPath + '/report/screenGroup/getScreenGroups'
        });
    },
    /**
     * 分页查询用户数据大屏
     * @param data {
          page: pagination.page,
          pageSize: pagination.pageSize,
          param: {...},
        }
     * @returns
     */
    queryReportScreenListPage: (data: any) => {
        return post({
            url: serverContextPath + '/report/screen/page',
            data: data,
        })
    },
    /**
     * 新增用户数据大屏
     * @param dataForm 参数
     * @returns
     */
    saveReportScreenInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/screen/save',
            data: dataForm,
        })
    },
    /**
     * 修改用户数据大屏
     * @param dataForm 参数
     * @returns
     */
    updateReportScreenInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/screen/update',
            data: dataForm,
        })
    },

    /**
     * 删除用户数据大屏
     * @param id 主键
     * @returns
     */
    deleteReportScreenInfo: (id: string) => {
        return post({
            url: serverContextPath + '/report/screen/remove/' + id,
        })
    },
    copyScreen: (id: string) => {
        return get({
            url: serverContextPath + '/report/screen/copy/' + id,
        })
    },
    getScreenByKey: (key: string) => {
        return get({
            url: serverContextPath + '/report/screen/key/' + key,
        })
    },
    getShareUrl: (key: string) => {
        return `${window.location.origin}/screen/${key}`
    },
    getPublishInfo: (key: string) => {
        return get({
            url: serverContextPath + '/report/screen/publish/' + key,
        })
    },
    viewScreen: (key: string) => {
        return get({
            url: serverContextPath + '/report/screen/view/' + key,
        })
    },
    checkPassword: (key: string, value: string) => {
        return post({
            url: serverContextPath + '/report/screen/checkPassword/',
            data:{ 'shareKey': key, 'password': value }
        })
    },
    hasPassword: (key: string) => {
        return get({
            url: serverContextPath + '/report/screen/hasPassword/' + key,
        })
    },
    getDatasetCharData: (chartType: string, datasetConfig: DatasetConfig) => {
        return post({
            url: serverContextPath + '/report/screen/getDatasetCharData',
            data: {
                'chartType': chartType,
                'sql': datasetConfig.sql,
                'dataSourceId': datasetConfig.dataSourceId,
            }
        })
    },
    /**
     * 分页查询报表 仪表盘
     * @param data {
          page: pagination.page,
          pageSize: pagination.pageSize,
          param: {...},
        }
     * @returns
     */
    queryReportPosterListPage: (data: any) => {
        return post({
            url: serverContextPath + '/report/poster/page',
            data: data,
        })
    },
    /**
     * 新增报表 仪表盘
     * @param dataForm 参数
     * @returns
     */
    saveReportPosterInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/poster/save',
            data: dataForm,
        })
    },
    /**
     * 修改报表 仪表盘
     * @param dataForm 参数
     * @returns
     */
    updateReportPosterInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/poster/update',
            data: dataForm,
        })
    },

    /**
     * 删除报表 仪表盘
     * @param id 主键
     * @returns
     */
    deleteReportPosterInfo: (id: string) => {
        return post({
            url: serverContextPath + '/report/poster/remove/' + id,
        })
    },
    /**
     * 获取报仪盘详细信息
     * @param key 
     * @returns 
     */
    getPosterByKey: (key: string) => {
        return get({
            url: serverContextPath + '/report/poster/key/' + key,
        })
    },
    generateFormDataPoster: (linkKey: string, dataId: string) => {
        return get({
            url: serverContextPath + '/report/poster/generate/' + linkKey + '/' + dataId,
        })
    },
    /**
     * 分页查询报表 仪表盘
     * @param data {
          page: pagination.page,
          pageSize: pagination.pageSize,
          param: {...},
        }
     * @returns
     */
    queryReportDashboardPageListPage: (data: any) => {
        return post({
            url: serverContextPath + '/report/dashboardPage/page',
            data: data,
        })
    },
    /**
     * 新增报表 仪表盘
     * @param dataForm 参数
     * @returns
     */
    saveReportDashboardPageInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/dashboardPage/save',
            data: dataForm,
        })
    },
    /**
     * 修改报表 仪表盘
     * @param dataForm 参数
     * @returns
     */
    updateReportDashboardPageInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/dashboardPage/update',
            data: dataForm,
        })
    },

    /**
     * 删除报表 仪表盘
     * @param id 主键
     * @returns
     */
    deleteReportDashboardPageInfo: (id: string) => {
        return post({
            url: serverContextPath + '/report/dashboardPage/remove/' + id,
        })
    },
    getDashboardByKey: (key: string) => {
        return get({
            url: serverContextPath + '/report/dashboardPage/key/' + key,
        })
    },
    getDashboardById: (id: string) => {
        return get({
            url: serverContextPath + '/report/dashboardPage/getInfo/' + id,
        })
    },
    getDashboard: (id: string) =>{
        return get({
            url: serverContextPath + '/report/dashboardPage/getInfo/' + id,
        })
    },
    getDashboardList: () => {
        return get<DashboardPage[]>({
            url: serverContextPath + '/report/dashboardPage/getDashboardList',
        })
    },
    /**
     * 分页查询表单数据源
     * @param data {
          page: pagination.page,
          pageSize: pagination.pageSize,
          param: {...},
        }
     * @returns
     */
    queryReportFormDataSourceListPage: (data: any) => {
        return post({
            url: serverContextPath + '/report/formDataSource/page',
            data: data,
        })
    },
    /**
     * 新增表单数据源
     * @param dataForm 参数
     * @returns
     */
    saveReportFormDataSourceInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/formDataSource/save',
            data: dataForm,
        })
    },
    /**
     * 修改表单数据源
     * @param dataForm 参数
     * @returns
     */
    updateReportFormDataSourceInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/formDataSource/update',
            data: dataForm,
        })
    },

    /**
     * 删除表单数据源
     * @param id 主键
     * @returns
     */
    deleteReportFormDataSourceInfo: (id: string) => {
        return post({
            url: serverContextPath + '/report/formDataSource/remove/' + id,
        })
    },
    getFormList: () => {
        return get({
            url: serverContextPath + '/report/formDataSource/list',
        })
    },
    getFormFieldList: (formKey: string) => {
        return get({
            url: serverContextPath + '/report/dashboardPage/key/' + formKey,
        })
    },
    getFieldDistinct: (indexName: string, fieldId: string) => {
        return get<string[]>({
            url: serverContextPath + '/report/chart/field/distinct/' + indexName + '/' + fieldId,
        })
    },
    /**
     * 分页查询海报设计器表单关联
     * @param data {
          page: pagination.page,
          pageSize: pagination.pageSize,
          param: {...},
        }
     * @returns
     */
    queryReportPosterFormLinkListPage: (data: any) => {
        return post({
            url: serverContextPath + '/report/posterFormLink/page',
            data: data,
        })
    },
    /**
     * 新增海报设计器表单关联
     * @param dataForm 参数
     * @returns
     */
    saveReportPosterFormLinkInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/posterFormLink/save',
            data: dataForm,
        })
    },
    /**
     * 修改海报设计器表单关联
     * @param dataForm 参数
     * @returns
     */
    updateReportPosterFormLinkInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/posterFormLink/update',
            data: dataForm,
        })
    },

    /**
     * 删除海报设计器表单关联
     * @param id 主键
     * @returns
     */
    deleteReportPosterFormLinkInfo: (id: string) => {
        return post({
            url: serverContextPath + '/report/posterFormLink/remove/' + id,
        })
    },
    getPosterFormLinkList: (posterKey: string) => {
        return post({
            url: serverContextPath + '/report/posterFormLink/listKey/' + posterKey,
        })
    },
    /**
     * 分页查询海报模板表
     * @param data {
          page: pagination.page,
          pageSize: pagination.pageSize,
          param: {...},
        }
     * @returns
     */
    queryReportPosterTemplateListPage: (data: any) => {
        return post({
            url: serverContextPath + '/report/posterTemplate/page',
            data: data,
        })
    },
    /**
     * 新增海报模板表
     * @param dataForm 参数
     * @returns
     */
    saveReportPosterTemplateInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/posterTemplate/save',
            data: dataForm,
        })
    },
    /**
     * 修改海报模板表
     * @param dataForm 参数
     * @returns
     */
    updateReportPosterTemplateInfo: (dataForm: any) => {
        return post({
            url: serverContextPath + '/report/posterTemplate/update',
            data: dataForm,
        })
    },

    /**
     * 删除海报模板表
     * @param id 主键
     * @returns
     */
    deleteReportPosterTemplateInfo: (id: string) => {
        return post({
            url: serverContextPath + '/report/posterTemplate/remove/' + id,
        })
    },
    getPosterTemplateList: () => {
        return get({
            url: serverContextPath + '/report/posterTemplate/list',
        })
    },
    /**
     * 预览海报
     * @param data
     */
    previewPosterImage: (data: any) => {
        return post({
            url: serverContextPath + '/report/posterTemplate/preview/',
            data: data,
        })
    },
    useTemplateToPoster: (id: string, posterKey: string) => {
        return get({
            url: serverContextPath + '/report/posterTemplate/useTemplateToPoster/' + id + '/' + posterKey,
        })
    },
}